package com.ihunanren.weixin.module.screen.school;

import static com.google.common.base.Strings.isNullOrEmpty;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.citrus.turbine.Context;
import com.alibaba.citrus.turbine.Navigator;
import com.alibaba.citrus.turbine.dataresolver.Param;
import com.ihunanren.biz.result.Result;
import com.ihunanren.biz.result.ResultSupport;
import com.ihunanren.biz.weixin.ao.ISchoolCurriculumAO;
import com.ihunanren.biz.weixin.domain.school.SchoolCurriculum;
import com.ihunanren.common.SafeConvert;
import com.ihunanren.webx.UserTrackInfo;

public class SchoolCourse {

	@Autowired
	private HttpServletRequest request;
	@Autowired
	private ISchoolCurriculumAO schoolCurriculumAO;

	public void execute(@Param(name="id")String _id, Navigator nav,Context context) {
		
		UserTrackInfo trackInfo = new UserTrackInfo(request);
		Result result = new ResultSupport(false);
		if(trackInfo.isLogin()){
			result = schoolCurriculumAO.queryAllSchoolCurriculumByUser(trackInfo.getUserNick());
		}else{
			if(isNullOrEmpty(_id)){
				nav.forwardTo("/school/login");
				return;
			}
			result = schoolCurriculumAO.queryAllSchoolCurriculumByDefinedId(SafeConvert.toLong(_id, -1));
		}
		if (result.isSuccess()) {
			SchoolCurriculum schoolCurriculum = (SchoolCurriculum) result.getDefaultModel();
			context.put("schoolCurriculum", schoolCurriculum);
			context.put("login", trackInfo.isLogin());
		}else{
			nav.forwardTo("error");
		}
		
	}
}
